package org.annoflow.filter.perf;

import org.annoflow.audit.ContextTracker;
import org.annoflow.audit.Logger;
import org.annoflow.filter.FilterPoint;

public class TimerFilter implements FilterPoint {
	
	private static long timer = 0L;

	@Override
	public String getFilterCode() {
		return "org.annoflow.filter.perf.TimerFilter.startTimer($args);";
	}
	
	@Override
	public String getReturnFilterCode() {
		return "org.annoflow.filter.perf.TimerFilter.stopTimer($_);";
	}
	
	public static void startTimer(Object[] args) {
		timer = System.currentTimeMillis();
	}
	
	public static void stopTimer(Object value) {
		long diff = System.currentTimeMillis() - timer;
//		Logger.out(TimerFilter.class.getName(), 
//					ContextTracker.getInstance().getFilterContext(), 
//					null, 
//					"Took " + diff + " ms.");
		
		System.out.println(diff);
	}

}
